<template>
    <div>
      <h2>登录</h2>
      <form @submit.prevent="handleSubmit">
        <label for="username">用户名:</label>
        <input v-model="username" type="text" id="username" required>
        <br>
        <label for="password">密码:</label>
        <input v-model="password" type="password" id="password" required>
        <br>
        <button type="submit">登录</button>
      </form>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  
  const username = ref('')
  const password = ref('')
  const router = useRouter()
  
  const handleSubmit = () => {
    if (username.value === 'admin') {
      localStorage.setItem('role', 'admin')
    } else {
      localStorage.setItem('role','student')
    }
    router.push('/')
  }
  </script>